#include <iostream>
#include <map>
#include <string>
using namespace std;

typedef map<string,float> StringFloatMap;

int main()
{
  StringFloatMap stocks; //pair<stock's name, prices>
  StringFloatMap::const_iterator c_iter;
  StringFloatMap::iterator iter;
  StringFloatMap::const_reverse_iterator c_r_iter;
  StringFloatMap::reverse_iterator r_iter;

  //insert value_type into map;
  stocks["BASF"] = 369.50f;
  stocks["VW"] = 413.50;
  stocks["Daimler"] = 819.00;
  stocks["BMW"] = 834.00;
  stocks["Siemens"] = 842.20;
  //print all stocks;
  for(c_iter = stocks.begin(); c_iter!=stocks.end(); ++c_iter){
    cout<<"stock: "<<c_iter->first<<"\t"
	<<"price: "<<(*c_iter).second<<endl;
  }
  cout<<endl;
  //boom(double all stocks' prices
  for(iter = stocks.begin(); iter != stocks.end(); ++iter){
    iter->second = (*iter).second * 2;
  }

  //print all stocks in reverse order;
  for(c_r_iter = stocks.rbegin(); c_r_iter != stocks.rend(); ++c_r_iter) {
    cout<<"stock: "<<(*c_r_iter).first<<"\t"
	<<"price: "<<(*c_r_iter).second<<endl;
  }
  cout<<endl;
  //rename stock name //the crux is you can't change the key directly
  stocks["Volkswagen"] = stocks["VW"];
  stocks.erase("VW");

  //print all stocks in reverse order;
  for(r_iter = stocks.rbegin(); r_iter != stocks.rend(); ++r_iter) {
    cout<<"stock: "<<r_iter->first<<"\t"
	<<"price: "<<r_iter->second<<endl;
  }
  return 0;
}
